package com.kuaiditu.assistant.api.xz_api.xz_encode;

/**
 * Created by Eenie on 2017/8/11.
 * Email: eeniework@gmail.com
 * Des:
 */

public abstract class b {

    private final int a;
    protected final byte b = (byte)61;
    protected final int c;
    protected byte[] d;
    protected int e;
    protected boolean f;
    protected int g;
    protected int h;
    private final int i;
    private final int j;
    private int k;

    protected b(int var1, int var2, int var3, int var4) {
        this.a = var1;
        this.i = var2;
        if(var3 > 0 && var4 > 0) {
            var1 = var3 / var2 * var2;
        } else {
            var1 = 0;
        }

        this.c = var1;
        this.j = var4;
    }

    private void c() {
        if(this.d == null) {
            this.d = new byte[this.b()];
            this.e = 0;
            this.k = 0;
        } else {
            byte[] var1 = new byte[this.d.length * 2];
            System.arraycopy(this.d, 0, var1, 0, this.d.length);
            this.d = var1;
        }

    }

    private void d() {
        this.d = null;
        this.e = 0;
        this.k = 0;
        this.g = 0;
        this.h = 0;
        this.f = false;
    }

    int a() {
        int var1;
        if(this.d != null) {
            var1 = this.e - this.k;
        } else {
            var1 = 0;
        }

        return var1;
    }

    protected void a(int var1) {
        if(this.d == null || this.d.length < this.e + var1) {
            this.c();
        }

    }

    abstract void a(byte[] var1, int var2, int var3);

    protected abstract boolean a(byte var1);

    protected int b() {
        return 8192;
    }

    int b(byte[] var1, int var2, int var3) {
        if(this.d != null) {
            var3 = Math.min(this.a(), var3);
            System.arraycopy(this.d, this.k, var1, var2, var3);
            this.k += var3;
            var2 = var3;
            if(this.k >= this.e) {
                this.d = null;
                var2 = var3;
            }
        } else if(this.f) {
            var2 = -1;
        } else {
            var2 = 0;
        }

        return var2;
    }

    public byte[] b(byte[] var1) {
        this.d();
        byte[] var2 = var1;
        if(var1 != null) {
            if(var1.length == 0) {
                var2 = var1;
            } else {
                this.a(var1, 0, var1.length);
                this.a(var1, 0, -1);
                var2 = new byte[this.e - this.k];
                this.b(var2, 0, var2.length);
            }
        }

        return var2;
    }

    protected boolean c(byte[] var1) {
        boolean var4 = false;
        boolean var3;
        if(var1 == null) {
            var3 = var4;
        } else {
            int var2 = 0;

            while(true) {
                var3 = var4;
                if(var2 >= var1.length) {
                    break;
                }

                if(61 == var1[var2] || this.a(var1[var2])) {
                    var3 = true;
                    break;
                }

                ++var2;
            }
        }

        return var3;
    }

    public long d(byte[] var1) {
        long var4 = (long)((var1.length + this.a - 1) / this.a) * (long)this.i;
        long var2 = var4;
        if(this.c > 0) {
            var2 = var4 + ((long)this.c + var4 - 1L) / (long)this.c * (long)this.j;
        }

        return var2;
    }
}
